/*
 * Copyright (c) 2023 Cshoo Org. All Rights Reserved.
 */

package org.tattoo.workflow.domain.repository;

import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.transaction.annotation.Transactional;
import org.tattoo.workflow.domain.po.ProcurementItem;

import java.util.List;

/**
 * @author 杨翼
 * @since 1.0
 */
public interface IProcurementItemRepository extends CrudRepository<ProcurementItem, Long> {
    /**
     * 修改采购订单明细
     * 这里只修改编号和数量字段
     *
     * @param procurementItem 采购明细
     */
    @Query("update ProcurementItem procurementItem set procurementItem.code = :#{#procurementItem.code},procurementItem.name = :#{#procurementItem.name}, procurementItem.count = :#{#procurementItem.count}, procurementItem.lastUpdatedBy = :#{#procurementItem.lastUpdatedBy}, procurementItem.lastUpdateTime = :#{#procurementItem.lastUpdateTime} where procurementItem.id = :#{#procurementItem.id}")
    @Modifying
    @Transactional(rollbackFor = Exception.class)
    void updateProcurementItem(ProcurementItem procurementItem);

    /**
     * 查询采购明细
     *
     * @param procurementOrderId 采购订单id
     * @return 采购明细
     */
    List<ProcurementItem> findByProcurementOrderId(Long procurementOrderId);
}
